<template>
  <van-nav-bar title="佣金" left-text="" left-arrow @click-left="goBack" />

  <div class="kickback_header">
    <div class="left">
      <div>
        可提现(元): <span>{{ total }}</span>
      </div>
      <div>累计提现(元): <span>4.00</span></div>
    </div>
    <div class="right">立即提现</div>
  </div>

  <div class="kickback">
    <div class="item" v-for="item in list" :key="item.id">
      <div class="left">
        <div class="img">
          <img :src="item.orderproductinfo[0].product.thumbs_text" alt="" />
        </div>
        <div class="content">
          <div class="nickname">订单号：{{ item.orders.code }}</div>
          <div class="tel">商品名称：{{ item.name }}</div>
        </div>
      </div>
      <div class="right">
        <div class="status">
          {{ (item.status = "0" ? "未体现" : "已体现") }}
        </div>
        <div class="money">+{{ item.amount }}</div>
      </div>
    </div>
  </div>
</template>
  
  <script setup>
import { computed, onBeforeMount, ref } from "vue";

const { proxy } = getCurrentInstance();

const LoginUser = reactive(proxy.$cookies.get("LoginUser"));

//挂载
onBeforeMount(() => {
  getCommissionInfo();
});
const goBack = () => {
  proxy.$router.go(-1);
};

const page = ref("1");
const limit = ref("5");
const status = ref("product");
const list = ref({});
const orderlist = ref([[]]);
const count = ref(0);
const getCommissionInfo = async () => {
  let result = await Api.Commission({
    page: page.value,
    limit: limit.value,
    status: status.value,
    busid: LoginUser.id,
  });

  console.log(result);
  console.log(result.data);
  if (result.code == 1) {
    list.value = result.data;
    list.value.forEach((item) => {
      const names = item.orderproductinfo.map((mm) => mm.product.name);
      item.name = names.join(", ");
    });

    console.log(list.value);
    // count.value=sum(list.value.amount);
    // console.log(count.value)
  }
};
const total = computed((item) => {
  let lists = list.value;
  let sum = 0;
  for (let i = 0; i < lists.length; i++) {
    sum += parseFloat(lists[i].amount);
  }
  return sum;//list.value.reduce((sum, item) => sum + parseFloat(item.amount), 0);
});
</script>
  
  <style scoped>
@import url("/assets/css/kickback.css");
</style>